﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace SharePoint.Orm.Helpers {
    public static class TypeHelper {
        ///<summary>
        /// Determines whether a given type is a descendant of another type
        ///</summary>
        ///<param name="type"></param>
        ///<param name="ancestor"></param>
        ///<returns></returns>
        public static bool IsDescendantOf(this Type type,Type ancestor) {
            if(type.BaseType == ancestor)
                return true;
            if(type.BaseType == typeof(object))
                return false;
            return IsDescendantOf(type.BaseType, ancestor);
        }
        ///<summary>
        /// Determines whether a given type is a ancestor of another type.
        ///</summary>
        ///<param name="type"></param>
        ///<param name="descendant"></param>
        ///<returns></returns>
        public static bool IsAncestorOf(this Type type,Type descendant) {
            return IsDescendantOf(descendant, type);
        }
    }
}
